<?php

namespace app\logic\single;

use app\api\model\music\MusicApiModel;
use app\api\model\music\MusicTypeApiModel;
use app\api\model\UserModel;
use app\logic\model\music\MusicLogicModel;
use app\logic\model\user\UserLogicModel;

class MusicSingle
{
    private static $inc;
    /**
     * @var MusicApiModel
     */
    private $musicModel;
    /**
     * @var UserModel
     */
    private $UserModel;

    protected $writer_field = ['id','writer_name','writer_head_img','fans_num'];
    private function __clone(){

    }

    public static function getInstance(){
        if(is_null(self::$inc)){
            self::$inc = new self();
        }
        return self::$inc;
    }
    function __construct()
    {
        $this->musicModel = new MusicApiModel();
        $this->UserModel = new UserModel();
    }

    function getMusicAndUser($music_id){
        $music = MusicLogicModel::getInfoById($music_id,'title,play_num,url,user_id,type_id')??[];
        if(empty($music)){
            $writer = [];
        }else{
            $writer = UserLogicModel::getInfoById($music['user_id'],$this->writer_field)??[];
            $music['type'] =MusicTypeApiModel::where('id',$music['type_id'])->field('title')->find();
        }
        return [$music,$writer];
    }
}